package com.sugon.dao;

import com.sugon.entity.SparePartCategory;
import com.sugon.entity.SparePartEntity;
import com.sugon.entity.vo.SparePartLifeCycleItem;
import com.sugon.utils.Query;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 备件清单Dao
 *
 * @author sugon
 * @date 2019-07-17 09:37:19
 */
public interface SparePartDao extends BaseDao<SparePartEntity> {

    /**
     * 获取备件对应的生命周期明细
     *
     * @param spId 备件ID
     * @return
     */
    List<SparePartLifeCycleItem> loadLifeCycleItem(@Param("spId") String spId);

    /**
     * 查询备件分类
     *
     * @return
     */
    @Select("select * from SPARE_PART_CATEGORY")
    List<SparePartCategory> listCategory();

    /**
     * 根据查询条件查询完全存在数
     *
     * @param map
     * @return
     */
    int queryExistsCount(Map<String, Object> map);

    /**
     * 查询完全匹配的总数
     *
     * @return
     */
    List<String> queryPerfectMatchedTotal(Map<String, Object> map);

    /**
     * 根据账外库备件编码查询备件信息
     *
     * @param originPartCode 账外库备件编码
     * @return
     */
    SparePartEntity queryByOriginPartCode(@Param("originPartCode") String originPartCode);

    /**
     * queryByCode
     *
     * @param partCode
     * @return
     */
    SparePartEntity queryByCode(@Param("partCode") String partCode);

    /**
     * 查看指定备件ID列表内的备件信息
     *
     * @param spIdList 备件ID列表
     * @return
     */
    List<SparePartEntity> queryListByIdList(@Param("spIdList") List<String> spIdList);

    /**
     * getSpconsume
     *
     * @param query
     * @return
     */
    List<SparePartEntity> getSpconsume(Query query);

    /**
     * querySpconsumeTotal
     *
     * @param query
     * @return
     */
    int querySpconsumeTotal(Query query);

    /**
     * 实时更新备件库存
     *
     * @param spareCode
     * @return
     */
    int realtimeUpdateStock(@Param("spareCode") String spareCode);

    /**
     * 实时更新备件在途数
     * 备件在途数由终版需要计划中的在途数累加获得
     *
     * @param spareCode
     * @return
     */
    int realtimeUpdateTransitNum(@Param("spareCode") String spareCode);

    /**
     * 实时更新备件报废数
     *
     * @param spareId
     * @return
     */
    int realtimeUpdateScarpNum(@Param("spareId") String spareId);

    /**
     * 统计备件年度的领用数
     *
     * @param spId     备件ID
     * @param lyYearly 领用年份
     * @return
     */
    @Select("SELECT CONSUMING_QUANTITY FROM SP_YEARLY_CONSUMING_RECORD WHERE SP_ID = #{spId} AND YEARLY = ${lyYearly}")
    Integer countYealySpLy(@Param("spId") String spId, @Param("lyYearly") Integer lyYearly);

    /**
     * 获取最新的设备编码
     *
     * @return
     */
    String getLastestPartCode();

}
